<?php

/**
 *
 */
class Hoadon  extends CI_Model {
    private $so_hoadon;
    private $Status_so_hoadon;
    private $email_khachhang;
    private $Status_email_khachhang;
    private $phi_dichvu;
    private $Status_phi_dichvu;
    private $tong_tien;
    private $Status_tong_tien;
    private $hinhthuc_thanhtoan;
    private $Status_hinhthuc_thanhtoan;
    private $gh_ho_tendem;
    private $Status_gh_ho_tendem;
    private $gh_ten;
    private $Status_gh_ten;
    private $gh_sonha_tenduong;
    private $Status_gh_sonha_tenduong;
    private $gh_phuong_xa;
    private $Status_gh_phuong_xa;
    private $gh_quan_huyen;
    private $Status_gh_quan_huyen;
    private $gh_tinh_tp;
    private $Status_gh_tinh_tp;
    private $gh_ma_buuchinh;
    private $Status_gh_ma_buuchinh;
    private $gh_sdt;
    private $Status_gh_sdt;
    private $trangthai_giaohang;
    private $Status_trangthai_giaohang;
    private $ngaylap_hoadon;
    private $Status_ngaylap_hoadon;
    private $ngay_giaohang;
    private $Status_ngay_giaohang;
    private $ngay_dat_hang;
    private $Status_ngay_dat_hang;
    private $ngay_donggoi_ss;
    private $Status_ngay_donggoi_ss;
    private $ngay_giaohang_thanhcong;
    private $Status_ngay_giaohang_thanhcong;
    private $baokim_transaction_status;
    private $Status_baokim_transaction_status;

    public function __construct() {
        parent::__construct();
        $this->load->database();
        $this->Oncreate();
   }

    private function Oncreate() {
        $this->so_hoadon = "";
        $this->Status_so_hoadon = 0;
        $this->email_khachhang = "";
        $this->Status_email_khachhang = 0;
        $this->phi_dichvu = "";
        $this->Status_phi_dichvu = 0;
        $this->tong_tien = "";
        $this->Status_tong_tien = 0;
        $this->hinhthuc_thanhtoan = "";
        $this->Status_hinhthuc_thanhtoan = 0;
        $this->gh_ho_tendem = "";
        $this->Status_gh_ho_tendem = 0;
        $this->gh_ten = "";
        $this->Status_gh_ten = 0;
        $this->gh_sonha_tenduong = "";
        $this->Status_gh_sonha_tenduong = 0;
        $this->gh_phuong_xa = "";
        $this->Status_gh_phuong_xa = 0;
        $this->gh_quan_huyen = "";
        $this->Status_gh_quan_huyen = 0;
        $this->gh_tinh_tp = "";
        $this->Status_gh_tinh_tp = 0;
        $this->gh_ma_buuchinh = "";
        $this->Status_gh_ma_buuchinh = 0;
        $this->gh_sdt = "";
        $this->Status_gh_sdt = 0;
        $this->trangthai_giaohang = "";
        $this->Status_trangthai_giaohang = 0;
        $this->ngaylap_hoadon = "";
        $this->Status_ngaylap_hoadon = 0;
        $this->ngay_giaohang = "";
        $this->Status_ngay_giaohang = 0;
        $this->ngay_dat_hang = "";
        $this->Status_ngay_dat_hang = 0;
        $this->ngay_donggoi_ss = "";
        $this->Status_ngay_donggoi_ss = 0;
        $this->ngay_giaohang_thanhcong = "";
        $this->Status_ngay_giaohang_thanhcong = 0;
        $this->baokim_transaction_status = "";
        $this->Status_baokim_transaction_status = 0;
    }

    public function set_so_hoadon($data) {
        $this->so_hoadon = $data;
        $this->Status_so_hoadon = 1;
    }

    public function set_email_khachhang($data) {
        $this->email_khachhang = $data;
        $this->Status_email_khachhang = 1;
    }

    public function set_phi_dichvu($data) {
        $this->phi_dichvu = $data;
        $this->Status_phi_dichvu = 1;
    }

    public function set_tong_tien($data) {
        $this->tong_tien = $data;
        $this->Status_tong_tien = 1;
    }

    public function set_hinhthuc_thanhtoan($data) {
        $this->hinhthuc_thanhtoan = $data;
        $this->Status_hinhthuc_thanhtoan = 1;
    }

    public function set_gh_ho_tendem($data) {
        $this->gh_ho_tendem = $data;
        $this->Status_gh_ho_tendem = 1;
    }

    public function set_gh_ten($data) {
        $this->gh_ten = $data;
        $this->Status_gh_ten = 1;
    }

    public function set_gh_sonha_tenduong($data) {
        $this->gh_sonha_tenduong = $data;
        $this->Status_gh_sonha_tenduong = 1;
    }

    public function set_gh_phuong_xa($data) {
        $this->gh_phuong_xa = $data;
        $this->Status_gh_phuong_xa = 1;
    }

    public function set_gh_quan_huyen($data) {
        $this->gh_quan_huyen = $data;
        $this->Status_gh_quan_huyen = 1;
    }

    public function set_gh_tinh_tp($data) {
        $this->gh_tinh_tp = $data;
        $this->Status_gh_tinh_tp = 1;
    }

    public function set_gh_ma_buuchinh($data) {
        $this->gh_ma_buuchinh = $data;
        $this->Status_gh_ma_buuchinh = 1;
    }

    public function set_gh_sdt($data) {
        $this->gh_sdt = $data;
        $this->Status_gh_sdt = 1;
    }

    public function set_trangthai_giaohang($data) {
        $this->trangthai_giaohang = $data;
        $this->Status_trangthai_giaohang = 1;
    }

    public function set_ngaylap_hoadon($data) {
        $this->ngaylap_hoadon = $data;
        $this->Status_ngaylap_hoadon = 1;
    }

    public function set_ngay_giaohang($data) {
        $this->ngay_giaohang = $data;
        $this->Status_ngay_giaohang = 1;
    }

    public function set_ngay_dat_hang($data) {
        $this->ngay_dat_hang = $data;
        $this->Status_ngay_dat_hang = 1;
    }

    public function set_ngay_donggoi_ss($data) {
        $this->ngay_donggoi_ss = $data;
        $this->Status_ngay_donggoi_ss = 1;
    }

    public function set_ngay_giaohang_thanhcong($data) {
        $this->ngay_giaohang_thanhcong = $data;
        $this->Status_ngay_giaohang_thanhcong = 1;
    }

    public function set_baokim_transaction_status($data) {
        $this->baokim_transaction_status = $data;
        $this->Status_baokim_transaction_status = 1;
    }

    public function get_so_hoadon() {
        return $this->so_hoadon;
    }

    public function get_email_khachhang() {
        return $this->email_khachhang;
    }

    public function get_phi_dichvu() {
        return $this->phi_dichvu;
    }

    public function get_tong_tien() {
        return $this->tong_tien;
    }

    public function get_hinhthuc_thanhtoan() {
        return $this->hinhthuc_thanhtoan;
    }

    public function get_gh_ho_tendem() {
        return $this->gh_ho_tendem;
    }

    public function get_gh_ten() {
        return $this->gh_ten;
    }

    public function get_gh_sonha_tenduong() {
        return $this->gh_sonha_tenduong;
    }

    public function get_gh_phuong_xa() {
        return $this->gh_phuong_xa;
    }

    public function get_gh_quan_huyen() {
        return $this->gh_quan_huyen;
    }

    public function get_gh_tinh_tp() {
        return $this->gh_tinh_tp;
    }

    public function get_gh_ma_buuchinh() {
        return $this->gh_ma_buuchinh;
    }

    public function get_gh_sdt() {
        return $this->gh_sdt;
    }

    public function get_trangthai_giaohang() {
        return $this->trangthai_giaohang;
    }

    public function get_ngaylap_hoadon() {
        return $this->ngaylap_hoadon;
    }

    public function get_ngay_giaohang() {
        return $this->ngay_giaohang;
    }

    public function get_ngay_dat_hang() {
        return $this->ngay_dat_hang;
    }

    public function get_ngay_donggoi_ss() {
        return $this->ngay_donggoi_ss;
    }

    public function get_ngay_giaohang_thanhcong() {
        return $this->ngay_giaohang_thanhcong;
    }

    public function get_baokim_transaction_status() {
        return $this->baokim_transaction_status;
    }

    /**
     *
     * Get  Oject
     *
     * @strWhere    Mệnh đề where
     * @return     no return. đưa các giá trị vào object gọi hàm()
     *
     */
    public function getObject($strWhere) {
        $this->Oncreate();
        $this->db->where($strWhere, NULL, FALSE);
        $query = $this->db->get("hoadon");
        $ar = $query->row_array();
        if (!empty($ar)) {
            $this->so_hoadon = $ar["so_hoadon"];
            $this->email_khachhang = $ar["email_khachhang"];
            $this->phi_dichvu = $ar["phi_dichvu"];
            $this->tong_tien = $ar["tong_tien"];
            $this->hinhthuc_thanhtoan = $ar["hinhthuc_thanhtoan"];
            $this->gh_ho_tendem = $ar["gh_ho_tendem"];
            $this->gh_ten = $ar["gh_ten"];
            $this->gh_sonha_tenduong = $ar["gh_sonha_tenduong"];
            $this->gh_phuong_xa = $ar["gh_phuong_xa"];
            $this->gh_quan_huyen = $ar["gh_quan_huyen"];
            $this->gh_tinh_tp = $ar["gh_tinh_tp"];
            $this->gh_ma_buuchinh = $ar["gh_ma_buuchinh"];
            $this->gh_sdt = $ar["gh_sdt"];
            $this->trangthai_giaohang = $ar["trangthai_giaohang"];
            $this->ngaylap_hoadon = $ar["ngaylap_hoadon"];
            $this->ngay_giaohang = $ar["ngay_giaohang"];
            $this->ngay_dat_hang = $ar["ngay_dat_hang"];
            $this->ngay_donggoi_ss = $ar["ngay_donggoi_ss"];
            $this->ngay_giaohang_thanhcong = $ar["ngay_giaohang_thanhcong"];
            $this->baokim_transaction_status = $ar["baokim_transaction_status"];
        }
    }

    /**
     *
     * Insert Object into database
     *
     */
    public function Save() {
        $data = array("so_hoadon" => $this->so_hoadon,"email_khachhang" => $this->email_khachhang,"phi_dichvu" => $this->phi_dichvu,"tong_tien" => $this->tong_tien,"hinhthuc_thanhtoan" => $this->hinhthuc_thanhtoan,"gh_ho_tendem" => $this->gh_ho_tendem,"gh_ten" => $this->gh_ten,"gh_sonha_tenduong" => $this->gh_sonha_tenduong,"gh_phuong_xa" => $this->gh_phuong_xa,"gh_quan_huyen" => $this->gh_quan_huyen,"gh_tinh_tp" => $this->gh_tinh_tp,"gh_ma_buuchinh" => $this->gh_ma_buuchinh,"gh_sdt" => $this->gh_sdt,"trangthai_giaohang" => $this->trangthai_giaohang,"ngaylap_hoadon" => $this->ngaylap_hoadon,"ngay_giaohang" => $this->ngay_giaohang,"ngay_dat_hang" => $this->ngay_dat_hang,"ngay_donggoi_ss" => $this->ngay_donggoi_ss,"ngay_giaohang_thanhcong" => $this->ngay_giaohang_thanhcong,"baokim_transaction_status" => $this->baokim_transaction_status);
        $this->db->insert("hoadon", $data);
    }

    /**
     *
     * Update Object có các field sử dụng hàm set_()
     *
     * @strWhere=null update tất cả các row trong database
     *
     */
    public function UpdateField($strWhere = NULL) {
        $arr = array();
        if ($this->Status_so_hoadon == 1)
            $arr["so_hoadon"] = $this->so_hoadon;
        if ($this->Status_email_khachhang == 1)
            $arr["email_khachhang"] = $this->email_khachhang;
        if ($this->Status_phi_dichvu == 1)
            $arr["phi_dichvu"] = $this->phi_dichvu;
        if ($this->Status_tong_tien == 1)
            $arr["tong_tien"] = $this->tong_tien;
        if ($this->Status_hinhthuc_thanhtoan == 1)
            $arr["hinhthuc_thanhtoan"] = $this->hinhthuc_thanhtoan;
        if ($this->Status_gh_ho_tendem == 1)
            $arr["gh_ho_tendem"] = $this->gh_ho_tendem;
        if ($this->Status_gh_ten == 1)
            $arr["gh_ten"] = $this->gh_ten;
        if ($this->Status_gh_sonha_tenduong == 1)
            $arr["gh_sonha_tenduong"] = $this->gh_sonha_tenduong;
        if ($this->Status_gh_phuong_xa == 1)
            $arr["gh_phuong_xa"] = $this->gh_phuong_xa;
        if ($this->Status_gh_quan_huyen == 1)
            $arr["gh_quan_huyen"] = $this->gh_quan_huyen;
        if ($this->Status_gh_tinh_tp == 1)
            $arr["gh_tinh_tp"] = $this->gh_tinh_tp;
        if ($this->Status_gh_ma_buuchinh == 1)
            $arr["gh_ma_buuchinh"] = $this->gh_ma_buuchinh;
        if ($this->Status_gh_sdt == 1)
            $arr["gh_sdt"] = $this->gh_sdt;
        if ($this->Status_trangthai_giaohang == 1)
            $arr["trangthai_giaohang"] = $this->trangthai_giaohang;
        if ($this->Status_ngaylap_hoadon == 1)
            $arr["ngaylap_hoadon"] = $this->ngaylap_hoadon;
        if ($this->Status_ngay_giaohang == 1)
            $arr["ngay_giaohang"] = $this->ngay_giaohang;
        if ($this->Status_ngay_dat_hang == 1)
            $arr["ngay_dat_hang"] = $this->ngay_dat_hang;
        if ($this->Status_ngay_donggoi_ss == 1)
            $arr["ngay_donggoi_ss"] = $this->ngay_donggoi_ss;
        if ($this->Status_ngay_giaohang_thanhcong == 1)
            $arr["ngay_giaohang_thanhcong"] = $this->ngay_giaohang_thanhcong;
        if ($this->Status_baokim_transaction_status == 1)
            $arr["baokim_transaction_status"] = $this->baokim_transaction_status;
        if (!empty($strWhere)) {
         $this->db->where($strWhere, NULL, FALSE);
        }
        $this->db->update("hoadon", $arr);
    }

    /**
     *
     * Get list Oject
     *
     * @strFieldName         Các field cần lấy dữ liệu
     * @strWhere             Mệnh đề where
     * @strOrderby           Ex: 'title desc, name asc'
     * @Limit_Number_Row     Số dòng dữ liệu cần lấy ra
     * @Limit_Start_Index    Vị trí bắt đầu lấy dữ liệu
     *     foreach ($t as $value) {
           $ob=(object)($value);
           echo $ob->hoadonname;
           echo $ob->pass;
       }
     * @return               result_object();
     *
     */
    public function getListObject($strFieldName = NULL, $strWhere = NULL, $strOrderby = NULL, $Limit_Number_Row = NULL, $Limit_Start_Index = NULL) {
        if (!is_null($strWhere)) {
            $this->db->where($strWhere, NULL, FALSE);
        }
        if (!is_null($strFieldName)) {
            $this->db->select($strFieldName);
        }
        if (!is_null($strOrderby)) {
            $this->db->order_by($strOrderby);
        }
        if (!is_null($Limit_Number_Row)) {
            if (!is_null($Limit_Start_Index))
                $this->db->limit($Limit_Number_Row, $Limit_Start_Index);
            else {
                $this->db->limit($Limit_Number_Row);
            }
        }
        $query = $this->db->get("hoadon");
        return $query->result_object();
    }

    /**
     *
     * Get list Oject
     *
     * @strWhere    Mệnh đề where. Null sẽ xóa hết dữ liệu của table
     * @return      no
     *
     */
    public function Delete($strWhere = NULL) {
        if (!is_null($strWhere)) {
            $this->db->where($strWhere, NULL, FALSE);
            $this->db->delete("hoadon");
        }        
       else $this->db->empty_table('hoadon');
    }

    /**
     *
     * Lây max giá trị kiểu int của 1 trường dữ liệu
     *
     * @strFieldName    Trường dữ liệu cần lấy max(1 trường duy nhất)
     * @strWhere        Mệnh đề where
     * @return          1 giá trị kiểu string
     *
     */
    public function Max($strFieldName, $strWhere = NULL) {
        if (!is_null($strWhere))
            $this->db->where($strWhere, NULL, FALSE);
        $this->db->select_max($strFieldName);
        $query = $this->db->get('hoadon');
        $ob = $query->row_array();
        return $ob[$strFieldName];
    }

}

?>